package com.gilgamesh.mall.product.controller;

import com.gilgamesh.mall.product.service.ProductDetailService;
import com.gilgamesh.mall.product.service.ProductService;
import com.gilgamesh.mall.sdk.dto.ResponseDTO;
import com.gilgamesh.mall.sdk.dto.product.ProductDTO;
import com.gilgamesh.mall.sdk.dto.product.Shop2DetailDTO;
import com.gilgamesh.mall.sdk.util.ResponseUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author yanm
 * @date 2021/1/26 11:01
 **/
@RestController
@RequestMapping("api/pdt")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@CrossOrigin
public class Shop2Controller {

    private final ProductService productService;

    private final ProductDetailService productDetailService;

    @PostMapping("listProductV2")
    public ResponseDTO<List<ProductDTO>> listProduct() {
        System.out.println("listProductV2 正在被调用");
        List<ProductDTO> pdos = productService.listProductV2();
        return ResponseUtil.getResponse(pdos);
    }

    @PostMapping("guessYouLikeV2")
    public List<ProductDTO> guessYouLikeV2(){
        System.out.println("guessYouLikeV2 猜你喜欢接口");
        List<ProductDTO> guess = productService.guessYouLikeV2();
        return guess;
    }

    @PostMapping("searchProductV2")
    public ResponseDTO<List<ProductDTO>> searchProduct(String keyWord) {
        System.out.println("searchProductV2 正在被调用   keyWord = "+keyWord);
        List<ProductDTO> pdos = productService.searchProductV2(keyWord);
        return ResponseUtil.getResponse(pdos);
    }

    @PostMapping("detailPageV2")
    public ResponseDTO<Shop2DetailDTO> detailPageV2(String productCode){
        System.out.println("detailPageV2 详情页请求  入参 productCode = " + productCode);
        Shop2DetailDTO shop2DetailDTO = productService.detailPageV2(productCode);
        return ResponseUtil.getResponse(shop2DetailDTO);
    }

    private final RedisTemplate redisTemplate;

}
